# Restful Api
from flask import jsonify


class HttpCode(object):
    # 响应正常
    ok = 200
    # 登陆失败
    unloginerror = 401
    # 没有权限
    permissionerror = 403
    # 客户端参数错误
    paramserror = 400
    # 服务器错误
    servererror = 500


def _restful_result(code, message, data):
    return jsonify({'message': message or "", 'data': data or {}, "code": code})


def ok(message=None, data=None):
    return _restful_result(HttpCode.ok, message, data)


def unlogin_error(message="没有登陆"):
    return _restful_result(HttpCode.unloginerror, message, {})


def permission_error(message="没有访问权限"):
    return _restful_result(HttpCode.permissionerror, message, {})


def params_error(message="参数错误！"):
    return _restful_result(HttpCode.paramserror, message, {})


def server_error(message="服务器错误"):
    return _restful_result(HttpCode.servererror, message=message or "服务器开小差了", data={})
